﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;



using Meqs.Entity;
using Meqs.Logic.Interface;

namespace Meqs.Logic.Implement
{
    public class MoralityDetailLogic : CommonLogic<MoralityDetail, int>, IMoralityDetailLogic
    {
        private ISchoolInfoLogic _schoolLogic;
        private IMoralityItemLogic _miLogic;
        public MoralityDetailLogic(ISchoolInfoLogic schoolLogic, IMoralityItemLogic miLogic)
        {
            _schoolLogic = schoolLogic;
            _miLogic = miLogic;
        }

        #region Implementation of ICommonLogic<MoralityDetail, int>

        /// <sammury>
        /// 创建对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Create(MoralityDetail entity)
        {
            return CreateObject(entity);
        }

        /// <sammury>
        /// 更新对象
        /// </sammury>
        /// <param name="entity"></param>
        /// <returns></returns>
        public int Update(MoralityDetail entity)
        {
            return UpdateObject(entity);
        }

        /// <summary>
        /// 删除对象
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public int Delete(int entityId)
        {
            return DeleteObject(entityId);
        }

        /// <summary>
        /// 删除所有对象
        /// </summary>
        /// <returns></returns>
        public int DeleteAll()
        {
            return DeleteAllObject();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="entityId"></param>
        /// <returns></returns>
        public MoralityDetail FindById(int entityId)
        {
            return FindObjectById(entityId);
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount()
        {
            return FindObjectByCount();
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<MoralityDetail> FindAll()
        {
            return FindAllObject();
        }

        /// <summary>
        /// 检索对象数量
        /// </summary>
        /// <returns></returns>
        public int FindCount(Hashtable table)
        {
            return FindObjectByCount(table);
        }

        /// <sammury>
        /// 检索对象
        /// </sammury>
        public IList<MoralityDetail> FindAll(Hashtable table)
        {
            return FindObject(table);
        }

        #endregion

        /// <summary>
        /// 获取班级下所有学生在指定的日期内的所有德育评价之明细
        /// </summary>
        /// <param name="studentID">学生ID</param>
        /// <param name="reportType">
        /// 报表类型
        /// 1:日报
        /// 2:周报
        /// 3:月报
        /// </param>
        /// <param name="year">报表年度</param>
        /// <param name="month">报表月度</param>
        /// <param name="schoolYear">学年，不填为当前学年</param>
        /// <param name="term">学期，不填为当前学期</param>
        /// <param name="schoolMark">学校编号</param>
        /// <returns></returns>
        public IList<ScoreInputEntity> GetScoreInputEntityByStudent(int studentID, int clsID, int reportType, int year,
                                int month, int day, int? schoolYear, int? term, string schoolMark)
        {
            if (schoolYear == null || term == null)
            {
                SchoolInfo school = _schoolLogic.FindBySchoolMark(schoolMark);
                schoolYear = school.SchoolYear;
                term = school.SchoolTerm;
            }
            Hashtable ht = new Hashtable();
            ht.Add("SchoolMark", schoolMark);
            ht.Add("StudentID", studentID);
            if (day==0)
                ht.Add("ReportDate", new DateTime(year, month, 1));
            else
                ht.Add("ReportDate", new DateTime(year, month, day));
            ht.Add("ReportType", reportType);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            ht.Add("ClsID", clsID);
            return FindCustomer<ScoreInputEntity>("MoralityDetail.GetScoreInputEntityByStudent", ht);
        }

        /// <summary>
        /// 保存
        /// </summary>
        /// <param name="moralityDetail"></param>
        /// <param name="schoolMark"></param>
        /// <returns></returns>
        public int InsertMoralityDetail(MoralityDetail moralityDetail, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("MoralityDetail", moralityDetail);
            ht.Add("SchoolMark", schoolMark);
            return (int)InsertCustomer("MoralityDetail.InsertMoralityDetail", ht);
        }

        private static string ReportDateType(int reportDateType)
        {
            switch (reportDateType)
            {
                case 1:
                    return "日";
                case 2:
                    return "周";
                case 3:
                    return "月度";
                default:
                    return "";
            }
        }

        public IList<MoralStuScore> GetStuMoralScore(String keyword ,int studentID, int? schoolYear, int? term, string schoolMark)
        {
            Hashtable ht = new Hashtable();
            ht.Add("KeyWord", keyword);
            ht.Add("SchoolMark", schoolMark);
            ht.Add("StudentID", studentID);
            ht.Add("SchoolYear", schoolYear);
            ht.Add("Term", term);
            return FindCustomer<MoralStuScore>("MoralityDetail.getStuMoralScore", ht);
        }
    }
}